#pragma once
#include "stdafx.h"
#include "BasisFunction.h"
#include <math.h>

BasisFunction::BasisFunction()
{

}

BasisFunction::~BasisFunction()
{

}

double BasisFunction::weight(double _distance,float _R)
{
	if(_distance > _R)
		return 0.0f;
	else
	{
		float scale = _distance/_R;
		double temp = 1.0f - scale;
		return (temp*temp*temp*(4.0*scale+1.0));
	}
}

double BasisFunction::weight(float x,float y,float z)
{
	float distance = sqrt((x-centerX)*(x-centerX)+(y-centerY)*(y-centerY)+(z-centerZ)*(z-centerZ));
	if(distance > supportSize)
		return 0;
	return weight(distance,supportSize);
}

double BasisFunction::implicitValue(float _x,float _y,float _z)
{
	float tempX = _x - centerX;
	float tempY = _y - centerY;
	float tempZ = _z - centerZ;
	double tempDistance = sqrt(tempX*tempX+tempY*tempY+tempZ*tempZ);
	if(tempDistance > supportSize)
		return 0;
	double tempWeight = weight(tempDistance,supportSize);
	double tempValue = (coordXX*tempX+coordXY*tempY+coordX)*tempX+
		               (coordYY*tempY+coordYZ*tempZ+coordY)*tempY+
					   (coordZZ*tempZ+coordZX*tempX+coordZ)*tempZ+
					    coordC;
	return tempWeight*tempValue;
}

BasisFunctionList::BasisFunctionList()
{

}

BasisFunctionList::BasisFunctionList(BasisFunction *_basisFunction)
{
	this->basisFunction = _basisFunction;
	next = NULL;
}

BasisFunctionList::~BasisFunctionList()
{
	if(next != NULL)
		delete next;
}
